from rest_framework import serializers

from goods.models import SpecificationOption, SPUSpecification


class SpecOptionSerializer(serializers.ModelSerializer):
    spec_id = serializers.IntegerField()
    spec = serializers.StringRelatedField(read_only=True)

    class Meta:
        model = SpecificationOption
        fields = ("id","value","spec","spec_id")
        extra_kwargs = {"spec":{"read_only":True}}
 # [
 #        {
 #            "id": "选项id",
 #            "value": "选项名称",
 #            "spec": "规格名称",
 #            "spec_id": "规格id"
 #        },
 #        ...
 #    ]


class SpecShowSerializer(serializers.ModelSerializer):
    class Meta:
        model = SPUSpecification
        fields = ("id","name")

 # [
 #        {
 #            "id": "规格id",
 #            "name": "规格名称"
 #        },
 #        ...
 #   ]
